package com.alm.token.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alm.token.R;
import com.alm.token.ui.activity.MessageActivity;
import com.alm.token.ui.activity.MessageDetailActivity;
import com.alm.token.ui.data.bean.UserWalletData;
import com.alm.token.utils.CommonUtil;
import com.wangxiandeng.swipecardrecyclerview.SwipeCardAdapter;

import java.util.List;

/**
 * Created by xingzhu on 2016/11/15.
 */

public class MyAdapter extends SwipeCardAdapter<MyAdapter.MyHolder> {
    private Context mContext;

    public MyAdapter(Context context, List<UserWalletData.DataBean.SysMsgBean> mList) {
        super(mList);
        mContext = context;
    }


    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_newwalletmessage_notice, parent, false);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        holder.title.setText(((UserWalletData.DataBean.SysMsgBean) mList.get(position)).getTitle());
        holder.date.setText(CommonUtil.getDateTimeFromMillisecond(((UserWalletData.DataBean.SysMsgBean) mList.get(position)).getCreateTime()).split(" ")[0]);
        holder.message.setText(((UserWalletData.DataBean.SysMsgBean) mList.get(position)).getContent());
        holder.message.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(mContext, MessageDetailActivity.class);
                intent1.putExtra("intentType", 1);
                intent1.putExtra("sysMsgBean", (UserWalletData.DataBean.SysMsgBean) mList.get(position));
                mContext.startActivity(intent1);
            }
        });
        holder.tv_click_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, MessageActivity.class);
                intent.putExtra("type", 1);
                mContext.startActivity(intent);
            }
        });
    }

    class MyHolder extends RecyclerView.ViewHolder {
        private TextView title;
        private TextView date;
        private TextView message;
        private TextView scandetail,tv_click_more;

        public MyHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.title);
            date = (TextView) itemView.findViewById(R.id.date);
            message = (TextView) itemView.findViewById(R.id.message);
            scandetail = itemView.findViewById(R.id.tv_click_scandetail);
            tv_click_more= itemView.findViewById(R.id.tv_click_more);
        }
    }
}
